package com.feng.online_xdclass.config;

import com.feng.online_xdclass.interceptor.CorsInterceptor;
import com.feng.online_xdclass.interceptor.LoginInterceptor;
import com.feng.online_xdclass.model.entity.User;
import com.feng.online_xdclass.utils.JsonDate;
import com.feng.online_xdclass.utils.UserThreadLocal;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;

/**
 * 拦截器配置
 * 不用权限访问url /api/v1/pub
 * 要用权限访问的url /api/v1/pri
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Bean
    LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }
    @Bean
    CorsInterceptor corsInterceptor(){
        return new CorsInterceptor();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * 拦截全部路劲，这个跨域的需要放在最上面
         */
        registry.addInterceptor(corsInterceptor()).addPathPatterns("/**");
        //拦截全部
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/api/v1/pri/*/*/**")
                //不拦截哪些路劲
                .excludePathPatterns("/api/v1/pri/user/login","/api/v1/pri/user/register");
        WebMvcConfigurer.super.addInterceptors(registry);

    }

}
